

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>roster_user_tools.cli_record_lib &mdash; Roster User Tools v0.17 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     'v0.17',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="Roster User Tools v0.17 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">Roster User Tools v0.17 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for roster_user_tools.cli_record_lib</h1><div class="highlight"><pre>
<span class="c">#!/usr/bin/python</span>

<span class="c"># Copyright (c) 2009, Purdue University</span>
<span class="c"># All rights reserved.</span>
<span class="c"># </span>
<span class="c"># Redistribution and use in source and binary forms, with or without</span>
<span class="c"># modification, are permitted provided that the following conditions are met:</span>
<span class="c"># </span>
<span class="c"># Redistributions of source code must retain the above copyright notice, this</span>
<span class="c"># list of conditions and the following disclaimer.</span>
<span class="c">#</span>
<span class="c"># Redistributions in binary form must reproduce the above copyright notice, this</span>
<span class="c"># list of conditions and the following disclaimer in the documentation and/or</span>
<span class="c"># other materials provided with the distribution.</span>
<span class="c"># </span>
<span class="c"># Neither the name of the Purdue University nor the names of its contributors</span>
<span class="c"># may be used to endorse or promote products derived from this software without</span>
<span class="c"># specific prior written permission.</span>
<span class="c"># </span>
<span class="c"># THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;</span>
<span class="c"># AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
<span class="c"># IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
<span class="c"># DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE</span>
<span class="c"># FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
<span class="c"># DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR</span>
<span class="c"># SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER</span>
<span class="c"># CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,</span>
<span class="c"># OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
<span class="c"># OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>

<span class="sd">&quot;&quot;&quot;Make record library for command line tools.&quot;&quot;&quot;</span>

<span class="n">__copyright__</span> <span class="o">=</span> <span class="s">&#39;Copyright (C) 2009, Purdue University&#39;</span>
<span class="n">__license__</span> <span class="o">=</span> <span class="s">&#39;BSD&#39;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s">&#39;#TRUNK#&#39;</span>


<span class="kn">import</span> <span class="nn">os</span>

<span class="kn">import</span> <span class="nn">roster_client_lib</span>
<span class="kn">import</span> <span class="nn">cli_common_lib</span>


<div class="viewcode-block" id="RecordNotFoundException"><a class="viewcode-back" href="../../roster_user_tools.html#roster_user_tools.cli_record_lib.RecordNotFoundException">[docs]</a><span class="k">class</span> <span class="nc">RecordNotFoundException</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
  <span class="k">pass</span>
</div>
<div class="viewcode-block" id="CliRecordLib"><a class="viewcode-back" href="../../roster_user_tools.html#roster_user_tools.cli_record_lib.CliRecordLib">[docs]</a><span class="k">class</span> <span class="nc">CliRecordLib</span><span class="p">:</span>
  <span class="sd">&quot;&quot;&quot;Command line record library class&quot;&quot;&quot;</span>
  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cli_common_lib_instance</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Gets cli common lib instance</span>
<span class="sd">    </span>
<span class="sd">    Inputs:</span>
<span class="sd">      cli_common_lib_instance: instance of cli common lib</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">cli_common_lib_instance</span> <span class="o">=</span> <span class="n">cli_common_lib_instance</span>

<div class="viewcode-block" id="CliRecordLib.MakeRecord"><a class="viewcode-back" href="../../roster_user_tools.html#roster_user_tools.cli_record_lib.CliRecordLib.MakeRecord">[docs]</a>  <span class="k">def</span> <span class="nf">MakeRecord</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_type</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">,</span>
                 <span class="n">allow_duplicate</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">quiet</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">raise_errors</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
                 <span class="n">fix_ptr_origin</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Connects to server and makes a DNS record.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      record_type: record type</span>
<span class="sd">      options: options object from optparse</span>
<span class="sd">      record_args_dict: dictionary varying according to record record_type</span>
<span class="sd">      allow_duplicate: allow duplicate entries without causing error</span>
<span class="sd">      quiet: whether or not function should be quiet</span>
<span class="sd">      raise_errors: raise errors rather than printing</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">record_args_dict</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="n">item</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">cli_common_lib</span><span class="o">.</span><span class="n">DnsError</span><span class="p">(</span><span class="s">&#39;Must specify --</span><span class="si">%s</span><span class="s">-</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">record_type</span><span class="p">,</span> <span class="n">item</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;_&#39;</span><span class="p">,</span> <span class="s">&#39;-&#39;</span><span class="p">)),</span> <span class="mi">1</span><span class="p">)</span>

    <span class="n">options</span><span class="o">.</span><span class="n">credfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">)</span>
    <span class="n">views</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span><span class="s">&#39;ListViews&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span>
                                          <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
                                          <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span>
                                          <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)[</span>
                                              <span class="s">&#39;core_return&#39;</span><span class="p">]</span>
    <span class="n">zones</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span><span class="s">&#39;ListZones&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span>
                                          <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
                                          <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span>
                                          <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)[</span>
                                              <span class="s">&#39;core_return&#39;</span><span class="p">]</span>
    <span class="n">search_target</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">target</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;ptr&#39;</span> <span class="p">):</span>
      <span class="n">search_target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
          <span class="s">&#39;GetPTRTarget&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
          <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span>
          <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">],</span>
          <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
    <span class="k">elif</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;aaaa&#39;</span> <span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">expanded_ip</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
            <span class="s">u&#39;ExpandIPV6&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
            <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]],</span> <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span>
            <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
        <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">expanded_ip</span>
    <span class="c">## Check if view exists</span>
    <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">views</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">)</span> <span class="ow">and</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="o">!=</span> <span class="s">&#39;any&#39;</span> <span class="p">):</span>
      <span class="n">cli_common_lib</span><span class="o">.</span><span class="n">DnsError</span><span class="p">(</span><span class="s">&#39;View does not exist!&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
    <span class="c">## Check if zone exists</span>
    <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">zones</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">zone_name</span><span class="p">)</span> <span class="p">):</span>
      <span class="n">cli_common_lib</span><span class="o">.</span><span class="n">DnsError</span><span class="p">(</span><span class="s">&#39;Zone does not exist!&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>

    <span class="n">records</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
        <span class="s">&#39;ListRecords&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
        <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="n">record_type</span><span class="p">,</span>
                                            <span class="s">&#39;target&#39;</span><span class="p">:</span> <span class="n">search_target</span><span class="p">,</span>
                                            <span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span><span class="p">,</span>
                                            <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">},</span>
        <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
    <span class="c">## Check for duplicate record</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">records</span> <span class="o">!=</span> <span class="p">[]</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">allow_duplicate</span> <span class="p">):</span>
      <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">records</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">record_arg</span> <span class="ow">in</span> <span class="n">record_args_dict</span><span class="p">:</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="n">record_arg</span><span class="p">]</span> <span class="o">!=</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="n">record_arg</span><span class="p">]</span> <span class="p">):</span>
            <span class="k">break</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="n">cli_common_lib</span><span class="o">.</span><span class="n">DnsError</span><span class="p">(</span><span class="s">&#39;Duplicate record!&#39;</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">fix_ptr_origin</span> <span class="ow">and</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;ptr&#39;</span> <span class="p">):</span>
        <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
            <span class="s">&#39;MakePTRRecord&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
            <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">],</span>
            <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">,</span> <span class="s">&#39;ttl&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">ttl</span><span class="p">)},</span>
            <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span> <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
            <span class="s">&#39;MakeRecord&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
            <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">record_type</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">],</span>
            <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">,</span> <span class="s">&#39;ttl&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">ttl</span><span class="p">)},</span>
            <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span> <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">options</span><span class="o">.</span><span class="n">ttl</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">options</span><span class="o">.</span><span class="n">ttl</span> <span class="o">=</span> <span class="s">u&#39;DEFAULT&#39;</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="p">):</span>
        <span class="n">arg_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">argument</span> <span class="ow">in</span> <span class="n">record_args_dict</span><span class="p">:</span>
          <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">:&#39;</span> <span class="o">%</span> <span class="n">argument</span><span class="p">)</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="n">argument</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
            <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;DEFAULT&#39;</span><span class="p">)</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">record_args_dict</span><span class="p">[</span><span class="n">argument</span><span class="p">]))</span>
        <span class="k">print</span> <span class="s">&#39;ADDED </span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s"> zone_name: </span><span class="si">%s</span><span class="s"> view_name: </span><span class="si">%s</span><span class="s"> ttl: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">record_type</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span><span class="p">,</span>
            <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">ttl</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&#39;    </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="s">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">arg_list</span><span class="p">)</span>
    <span class="k">elif</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;ptr&#39;</span> <span class="p">):</span>
      <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
          <span class="s">u&#39;MakePTRRecord&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
          <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">],</span>
          <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">,</span> <span class="s">&#39;ttl&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">ttl</span><span class="p">)},</span>
          <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span> <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">options</span><span class="o">.</span><span class="n">ttl</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">options</span><span class="o">.</span><span class="n">ttl</span> <span class="o">=</span> <span class="s">u&#39;DEFAULT&#39;</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="p">):</span>
        <span class="n">arg_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">argument</span> <span class="ow">in</span> <span class="n">record_args_dict</span><span class="p">:</span>
          <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">:&#39;</span> <span class="o">%</span> <span class="n">argument</span><span class="p">)</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="n">argument</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
            <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;DEFAULT&#39;</span><span class="p">)</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">record_args_dict</span><span class="p">[</span><span class="n">argument</span><span class="p">]))</span>
        <span class="k">print</span> <span class="s">&#39;ADDED PTR: </span><span class="si">%s</span><span class="s"> zone_name: </span><span class="si">%s</span><span class="s"> view_name: </span><span class="si">%s</span><span class="s"> ttl: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">,</span>
            <span class="n">options</span><span class="o">.</span><span class="n">ttl</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&#39;    </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="s">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">arg_list</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
          <span class="s">u&#39;MakeRecord&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
          <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">record_type</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span><span class="p">,</span>
          <span class="n">record_args_dict</span><span class="p">],</span>
          <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">,</span> <span class="s">&#39;ttl&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">ttl</span><span class="p">)},</span>
          <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span> <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">options</span><span class="o">.</span><span class="n">ttl</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">options</span><span class="o">.</span><span class="n">ttl</span> <span class="o">=</span> <span class="s">u&#39;DEFAULT&#39;</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="p">):</span>
        <span class="n">arg_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">argument</span> <span class="ow">in</span> <span class="n">record_args_dict</span><span class="p">:</span>
          <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">:&#39;</span> <span class="o">%</span> <span class="n">argument</span><span class="p">)</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="n">argument</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
            <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;DEFAULT&#39;</span><span class="p">)</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">record_args_dict</span><span class="p">[</span><span class="n">argument</span><span class="p">]))</span>
        <span class="k">print</span> <span class="s">&#39;ADDED </span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s"> zone_name: </span><span class="si">%s</span><span class="s"> view_name: </span><span class="si">%s</span><span class="s"> ttl: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">record_type</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span><span class="p">,</span>
            <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">ttl</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&#39;    </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="s">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">arg_list</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CliRecordLib.RemoveRecord"><a class="viewcode-back" href="../../roster_user_tools.html#roster_user_tools.cli_record_lib.CliRecordLib.RemoveRecord">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveRecord</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_type</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">,</span> <span class="n">quiet</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
                   <span class="n">raise_errors</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">fix_ptr_origin</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Connects to server and removes a DNS record.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      record_type: record type</span>
<span class="sd">      options: options object from optparse</span>
<span class="sd">      record_args_dict: dictionary varying according to record record_type</span>
<span class="sd">      quiet: whether or not function should be quiet</span>
<span class="sd">      raise_errors: raise errors rather than printing</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">record_args_dict</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="n">item</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">cli_common_lib</span><span class="o">.</span><span class="n">DnsError</span><span class="p">(</span><span class="s">&#39;Must specify --</span><span class="si">%s</span><span class="s">-</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">record_type</span><span class="p">,</span> <span class="n">item</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;_&#39;</span><span class="p">,</span> <span class="s">&#39;-&#39;</span><span class="p">)),</span> <span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;ptr&#39;</span> <span class="p">):</span>
      <span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
          <span class="s">&#39;GetPTRTarget&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
          <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span>
          <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">],</span>
          <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
    <span class="k">elif</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;aaaa&#39;</span> <span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">expanded_ip</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
            <span class="s">u&#39;ExpandIPV6&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
            <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]],</span> <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span>
            <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
        <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">expanded_ip</span>

    <span class="n">options</span><span class="o">.</span><span class="n">credfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">)</span>
    <span class="n">views</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
        <span class="s">&#39;ListViews&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
        <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">)[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
    <span class="n">zones</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
        <span class="s">&#39;ListZones&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
        <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span> <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
    <span class="c">## Check if view exists</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">views</span> <span class="ow">and</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="o">!=</span> <span class="s">&#39;any&#39;</span>  <span class="p">):</span>
      <span class="n">cli_common_lib</span><span class="o">.</span><span class="n">DnsError</span><span class="p">(</span><span class="s">&#39;View does not exist!&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
    <span class="c">## Check if zone exists</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">zones</span> <span class="p">):</span>
      <span class="n">cli_common_lib</span><span class="o">.</span><span class="n">DnsError</span><span class="p">(</span><span class="s">&#39;Zone does not exist!&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
    <span class="n">function</span> <span class="o">=</span> <span class="s">u&#39;RemoveRecord&#39;</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">fix_ptr_origin</span> <span class="ow">and</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;ptr&#39;</span> <span class="p">):</span>
      <span class="n">function</span> <span class="o">=</span> <span class="s">u&#39;RemovePTRRecord&#39;</span>
    <span class="n">removed_records</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
        <span class="n">function</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
        <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">record_type</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">,</span>
              <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">],</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;ttl&#39;</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">ttl</span><span class="p">)},</span>
        <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span> <span class="n">raise_errors</span><span class="o">=</span><span class="n">raise_errors</span><span class="p">)[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">removed_records</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">):</span>
      <span class="n">cli_common_lib</span><span class="o">.</span><span class="n">DnsError</span><span class="p">(</span>
          <span class="s">&#39;&quot;</span><span class="si">%s</span><span class="s">&quot; record with target &quot;</span><span class="si">%s</span><span class="s">&quot; in &quot;</span><span class="si">%s</span><span class="s">&quot; zone and &quot;</span><span class="si">%s</span><span class="s">&quot; view not found.&#39;</span><span class="p">,</span>
          <span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">options</span><span class="o">.</span><span class="n">view_name</span> <span class="o">=</span> <span class="s">u&#39;any&#39;</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">options</span><span class="o">.</span><span class="n">ttl</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">options</span><span class="o">.</span><span class="n">ttl</span> <span class="o">=</span> <span class="s">u&#39;DEFAULT&#39;</span>
    <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">quiet</span> <span class="p">):</span>
      <span class="n">arg_list</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="k">for</span> <span class="n">argument</span> <span class="ow">in</span> <span class="n">record_args_dict</span><span class="p">:</span>
        <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">:&#39;</span> <span class="o">%</span> <span class="n">argument</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="n">argument</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
          <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;DEFAULT&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="n">arg_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">record_args_dict</span><span class="p">[</span><span class="n">argument</span><span class="p">]))</span>
      <span class="k">print</span> <span class="s">&#39;REMOVED </span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s"> zone_name: </span><span class="si">%s</span><span class="s"> view_name: </span><span class="si">%s</span><span class="s"> ttl: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
          <span class="n">record_type</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span><span class="p">,</span>
          <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">ttl</span><span class="p">)</span>
      <span class="k">print</span> <span class="s">&#39;    </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="s">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">arg_list</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CliRecordLib.ListRecords"><a class="viewcode-back" href="../../roster_user_tools.html#roster_user_tools.cli_record_lib.CliRecordLib.ListRecords">[docs]</a>  <span class="k">def</span> <span class="nf">ListRecords</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_type</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists records given certain parameters</span>

<span class="sd">    Inputs:</span>
<span class="sd">      options: options object from optparse</span>
<span class="sd">      record_args_dict: record arguments dictionary</span>

<span class="sd">    Outputs:</span>
<span class="sd">      list or string depending on record type</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">search_target</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">target</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;ptr&#39;</span> <span class="ow">and</span> <span class="n">search_target</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">search_target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
          <span class="s">&#39;GetPTRTarget&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
          <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span>
          <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">options</span><span class="o">.</span><span class="n">target</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">])[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
    <span class="k">elif</span><span class="p">(</span> <span class="n">record_type</span> <span class="o">==</span> <span class="s">u&#39;aaaa&#39;</span> <span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
        <span class="n">expanded_ip</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
            <span class="s">u&#39;ExpandIPV6&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
            <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]],</span>
            <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">)[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
        <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">expanded_ip</span>
    <span class="n">records</span> <span class="o">=</span> <span class="n">roster_client_lib</span><span class="o">.</span><span class="n">RunFunction</span><span class="p">(</span>
        <span class="s">&#39;ListRecords&#39;</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">credfile</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">credfile</span><span class="p">,</span>
        <span class="n">server_name</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">server</span><span class="p">,</span>
        <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="n">record_type</span><span class="p">,</span> <span class="s">&#39;target&#39;</span><span class="p">:</span> <span class="n">search_target</span><span class="p">,</span>
                <span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">options</span><span class="o">.</span><span class="n">zone_name</span><span class="p">,</span> <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">options</span><span class="o">.</span><span class="n">view_name</span><span class="p">,</span>
                <span class="s">&#39;record_args_dict&#39;</span><span class="p">:</span> <span class="n">record_args_dict</span><span class="p">})[</span><span class="s">&#39;core_return&#39;</span><span class="p">]</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">record_type</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">records_type_dict</span> <span class="o">=</span> <span class="p">{}</span>
      <span class="n">return_list</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="n">print_list</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">records</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">records_type_dict</span> <span class="p">):</span>
          <span class="n">records_type_dict</span><span class="p">[</span><span class="n">record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">records_type_dict</span><span class="p">[</span><span class="n">record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">record</span><span class="p">)</span>
      <span class="k">for</span> <span class="n">record_type</span> <span class="ow">in</span> <span class="n">records_type_dict</span><span class="p">:</span>
        <span class="n">key_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">have_keys</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">no_header</span>
        <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">records_type_dict</span><span class="p">[</span><span class="n">record_type</span><span class="p">]:</span>
          <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">have_keys</span> <span class="p">):</span>
            <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">record</span><span class="p">:</span>
              <span class="n">key_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
            <span class="n">print_list</span> <span class="o">=</span> <span class="p">[</span><span class="n">key_list</span><span class="p">]</span>
            <span class="n">have_keys</span> <span class="o">=</span> <span class="bp">True</span>
          <span class="n">print_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">record</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
        <span class="n">return_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cli_common_lib</span><span class="o">.</span><span class="n">PrintColumns</span><span class="p">(</span>
            <span class="n">print_list</span><span class="p">,</span> <span class="n">first_line_header</span><span class="o">=</span><span class="p">(</span><span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">no_header</span><span class="p">)))</span>
      <span class="k">return</span> <span class="n">return_list</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">have_keys</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">no_header</span>
      <span class="n">key_list</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="n">print_list</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">records</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">have_keys</span> <span class="p">):</span>
          <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">record</span><span class="p">:</span>
            <span class="n">key_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
          <span class="n">print_list</span> <span class="o">=</span> <span class="p">[</span><span class="n">key_list</span><span class="p">]</span>
          <span class="n">have_keys</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="n">print_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">record</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
      <span class="k">return</span> <span class="n">cli_common_lib</span><span class="o">.</span><span class="n">PrintColumns</span><span class="p">(</span>
          <span class="n">print_list</span><span class="p">,</span> <span class="n">first_line_header</span><span class="o">=</span><span class="p">(</span><span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">no_header</span><span class="p">))</span></div></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">Roster User Tools v0.17 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Purdue University.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>